<?php
/**
* @file addresslistm.php
* @synopsis  提交问题报告
* @author Yee, <rlk002@gmail.com>
* @version 1.0
* @date 2015年7月7日11:08:26
*/


class Addresslistm extends CI_Model
{
	function __construct()
	{
		
	}

	//提交问题报告
	public function insert_addresslist($query)
	{
		return $this->db->insert("ml_address_list",$query);
	}

	public function is_cellphone_exists($cellphone,$uid)
	{
		return $this->db->select()->from('ml_address_list')->where(array("uid"=>$uid,"cellphone"=>$cellphone))->get()->result_array();
	}

	public function update_addresslist($set,$where)
	{
		$this->db->set($set)->where($where)->update('ml_address_list');
	}

	//获取通讯录
	public function get_addresslist($uid)
	{
        $mc = $this->cache->memcached;
        $key = 'get_addresslistm_' . $uid;
        if(!$this->cache->memcached->is_supported())
        {
            $result = array("code" => -3,'tips' => "缓存未开启");
        }
        $data_content = $mc->get($key);
        if($data_content)
        {
            return $data_content;
        }
        $data_content = $this->db->select()->from('ml_address_list')->where(array("uid"=>$uid))->get()->result_array();
        $mc->save($key,$data_content,5*60);
		return $data_content;
	}

    //获取通讯录
    public function get_addresslist_cellphone($uid)
    {
        $mc = $this->cache->memcached;
        $key = 'get_addresslist_cellphone_' . $uid;
        if(!$this->cache->memcached->is_supported())
        {
            $result = array("code" => -3,'tips' => "缓存未开启");
        }
        $data_content = $mc->get($key);
        if($data_content)
        {
            return $data_content;
        }
        $data_content = $this->db->select("cellphone")->from('ml_address_list')->where(array("uid"=>$uid))->get()->result_array();
        $mc->save($key,$data_content,10*60);
        return $data_content;
    }

	public function getUserIdByCellphoneForAddresslist($cellphone)
    {
        $userinfo = array();

        $mc = $this->cache->memcached;
        $key = 'getUserIdByCellphone_' . $cellphone;
        if(!$this->cache->memcached->is_supported())
        {
            $result = array("code" => -3,'tips' => "缓存未开启");
        }

        $data_content = $mc->get($key);
        if($data_content)
        {
        	//w_log("mac is ".json_encode($data_content));
            $userinfo = $data_content;
        }
        else
        {
            $data_content = $this->db->select("id")->from('ml_fellow')->where('cellphone',$cellphone)->where('is_show',1)->get()->result_array();
            //w_log("mysql  is ".json_encode($data_content));
            $mc->save($key,$data_content, 5*24*60*60);
            $userinfo = $data_content;
        }

        return $userinfo[0];
    }
}